/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.yandex.sumofseries.threads;

import static java.lang.Math.*;

/**
 *
 * @author Neophron
 */
public class MyThread {

    private final double from, to;
    private volatile double result;
    private volatile boolean isChecked = false;

    private volatile boolean isResultReady = false;

    private class Calc implements Runnable {

        @Override
        public void run() {
            double x = from;
            while (x <= to) {
                result += sin(x) * cos(x);
                x += Sum.STEP;
            }
            isResultReady = true;
        }

    }

    MyThread(double from, double to) {
        this.from = from;
        this.to = to;
        result = 0;
    }
    
    public void start() {
        Thread t = new Thread(new Calc());
        t.start();
    }
    
    public boolean isResultReady() {
        return isResultReady;
    }
    
    public boolean isChecked() {
        return isChecked;
    }
    
    public double getResult() {
        isChecked = true;
        return result;
    }

}
